package com.kobe.game_20;

import java.util.LinkedList;

public class Game_5 {

    /**
     * 2520 is the smallest number that can be divided by each of the numbers
     * from 1 to 10 without any remainder.
     * 
     * What is the smallest number that is evenly divisible by all of the
     * numbers from 1 to 20?
     * 
     * The result is : 232792560
     */
    public static void main(String[] args) {
        int result = 1;
        for (Integer factors : getFactorsIncrement(20)) {
            result = result * factors;
        }
        System.out.println("The result is : " + result);
    }

    /**
     * to get all the factors increment from 1 to the given number
     */
    private static LinkedList<Integer> getFactorsIncrement(int in) {
        LinkedList<Integer> factorsIncre = new LinkedList<Integer>();
        int loopNumber = 0;

        for (int i = 2; i <= in; i++) {
            loopNumber = i;
            for (Integer tempFactors : factorsIncre) {
                if (loopNumber % tempFactors == 0) {
                    loopNumber = loopNumber / tempFactors;
                }
            }
            factorsIncre.add(loopNumber);
        }
        return factorsIncre;
    }
}
